class AnnouncementsSweeper < ActionController::Caching::Sweeper
  observe Announcement # This sweeper is going to keep an eye on the Announcement model

  def after_save(announcement)
    expire_cache_for(announcement)
  end

  def after_destroy(announcement)
    expire_cache_for(announcement)
  end
  
  def after_apo_post_admin
    expire_cache_for(assigns(:announcement))
  end

  def after_apo_post_member
    expire_cache_for(assigns(:announcement))
  end

  def after_apo_delete_post
    expire_cache_for(assigns(:announcement))
  end
  
  private
  def expire_cache_for(announcement)
    expire_cache
  end
  
  def expire_cache
    expire_fragment(%r(apo/home\?action_suffix=announcements_.*))
  end
end
